package com.szl.group.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * mybatis-plus自动填充处理器
 * 控制创建时间和修改时间
 *
 * @author shenxiaolong.
 * @time 2020/6/26
 */
@Component
public class MetaHandler implements MetaObjectHandler/*, HandlerInterceptor*/ {

    @Override
    public void insertFill(MetaObject metaObject) {
        //属性名称，不是字段名称
        /*  String username =(String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        this.setFieldValByName("creteBy","admin",metaObject);//先暂时以admin代替*/
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("lastModifiedTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
      /*  String username =(String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        this.setFieldValByName("updateBy","admin",metaObject);*/
        this.setFieldValByName("lastModifiedTime", new Date(), metaObject);
    }

}
